package com.aqie.easy.tree;

import com.aqie.easy.structure.TreeNode;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 965. 单值二叉树
 * 二叉树 ：
 */
public class IsUnivalTree {
    /**
     * 二叉树遍历
     * @param root
     * @return
     * 1
     * 0
     * [1,1,1,1,1,null,1]
     * [1,1]
     * [2,2,2,5,2]
     */
    Set<Integer> set = new HashSet<>();

    public boolean isUnivalTree(TreeNode root) {
        if (root == null) return false;
        if (root.left == null && root.right == null) return true;

        traverse(root);
        return set.size() == 1;
    }

    public void traverse(TreeNode node){
            if (node != null) {
                set.add(node.val);
                traverse(node.left);
                traverse(node.right);
            }
    }

    public static void main(String[] args) {
        Map<Integer,Integer> map = new HashMap<>();
        Integer put1 = map.put(1, 2);
        System.out.println(put1);
        Integer put2 = map.put(1, 3);
        System.out.println(put2);

    }
}
